'use strict'

const Promise = require('bluebird')

const mysql = require('../lib/mysql')

exports.getUserByOpenid = function(openid) {
  return new Promise(function(resolve,reject){
    mysql.queryOneAsync('SELECT nickname FROM user WHERE openid = ?',openid).then(function(user){
     resolve(user)
    })
  })
}

exports.bindAccount = function(account,password,openid) {
  return new Promise(function(resolve,reject){
    mysql.queryAsync('UPDATE user SET openid = ? WHERE account = ? AND password = ?',[openid,account,password]).then(function(rows){
      resolve(rows.affectedRows)
    })
  })
}